package com.zhuchaooasystem.presenter.home.fragment.oa.record;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;

import com.zhuchaooasystem.R;
import com.zhuchaooasystem.base.BasePresenter;
import com.zhuchaooasystem.utils.FileUtils;
import com.zhuchaooasystem.utils.ToastUtil;
import com.zhuchaooasystem.widget.ConfirmDialog;

/**
 * @author yinsi
 */


public class TakeRecordPresenter extends BasePresenter<TakeRecordContract.View> implements TakeRecordContract.Presenter {

    public TakeRecordPresenter(Activity activity, TakeRecordContract.View view) {
        super(activity, view);
    }

    /**
     * 弹窗提示是否要关闭
     */
    @Override
    public void showDialog() {
        ConfirmDialog dialog = new ConfirmDialog(mActivity);
        dialog.show();
        dialog.setTextTitle("提示");
        dialog.setTextContent("确定要放弃当前录音？");
        dialog.setOnViewClickListener(new ConfirmDialog.OnViewClickListener() {
            @Override
            public void onClickOk(ConfirmDialog dialog) {
                dialog.dismiss();
                mView.exit();
            }

            @Override
            public void onClickCancel(ConfirmDialog dialog) {
                dialog.dismiss();
            }
        });

    }

    /**
     * 检测当前环境
     */
    @Override
    public boolean checkEnviroment() {
        // 检测SD卡
        if (!FileUtils.sdCardExists()) {
            ToastUtil.showShort(mActivity, mActivity.getResources().getString(R.string.record_txt_toast_wrong_environment));
            return false;
        } else {
            return true;
        }
    }


    /**
     * 检测录音权限
     */
    @Override
    public void checkCameraPermission() {
        if (ActivityCompat.checkSelfPermission(mActivity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(mActivity, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
            ToastUtil.showShort(mActivity, "请打开本应用的录音权限");
        }
    }


}
